﻿<!DOCTYPE html>
<html>
    <head>
        <title>Install</title>
    </head>
    <body>
    @{
        if (IsPost)
        {
            // First save the system mail settings
            Settings.SystemMailSettings.SmtpServer = Request.Params["SmtpServer"];
            Settings.SystemMailSettings.UserName = Request.Params["UserName"];
            Settings.SystemMailSettings.Password = Request.Params["Password"];
            Settings.SystemMailSettings.Website = Request.Params["Website"];
            Settings.SystemMailSettings.From = Request.Params["From"];
            Settings.SystemMailSettings.FromName = Request.Params["FromName"];
            Settings.SystemMailSettings.To = Request.Params["To"];
            Settings.SystemMailSettings.ToName = Request.Params["ToName"];
            Settings.SystemMailSettings.Save(); 
            if (this.Request.Params["submit"] == "Save")
            {               
                // Now save the log reporting settings.
                Settings.LogSubscribers.Clear();
                for(int i = 0; i < 1000; ++i)
                {
                    var email = Request.Params["email" + i.ToString()];
                    if (!String.IsNullOrEmpty(email))
                    {
                        Settings.LogSubscribers.Add(email, (Request.Params["log" + i.ToString()] != null), (Request.Params["err" + i.ToString()] != null), (Request.Params["dmp" + i.ToString()] != null));
                    }
                }
                Settings.LogSubscribers.Save();
                <p>Settings saved</p>
            }
            else if (this.Request.Params["submit"] == "Test")
            {
                Mail.Simple("Test email", "This is email address.");
            }
        }
    }
    <form action="" method="post" style="background-color:#DDD">
    <table>
    <tr><td colspan="4"><h2>System wide mail settings:</h2></td></tr>
    <tr><td>SmtpServer:</td><td><input type="text" name="SmtpServer" value="@Settings.SystemMailSettings.SmtpServer" /></td><td>UserName:</td><td><input type="text" name="UserName" value="@Settings.SystemMailSettings.UserName" /></td></tr>
    <tr><td>Website:</td><td><input type="text" name="Website" value="@Settings.SystemMailSettings.Website" />(Indentifier as to which website this log comes from)</td><td>Password:</td><td><input type="text" name="Password" value="@Settings.SystemMailSettings.Password" /></td></tr>
    <tr><td>From Email:</td><td><input type="text" name="From" value="@Settings.SystemMailSettings.From" />(Default from email address)</td><td>From Email Name:</td><td><input type="text" name="FromName" value="@Settings.SystemMailSettings.FromName" />(Name of sender)</td></tr>
    <tr><td>To Email:</td><td><input type="text" name="To" value="@Settings.SystemMailSettings.To" />(Default to email address)</td><td>To Email Name:</td><td><input type="text" name="ToName" value="@Settings.SystemMailSettings.ToName" />(Default name of receiver)</td></tr>
    <tr><td colspan="4"><input type="submit" name="submit" value="Test" /></td></tr>
    <tr><td colspan="4"><input type="submit" name="submit" value="Save" /></td></tr>
    </table>
    <table>
    <tr><td colspan="4"><h2>System Log File Subscribers:</h2></td></tr>
      @{
          int j = 0;
          foreach (var subscriber in Settings.LogSubscribers.Subscribers)
          {
            <tr><td>Email:</td><td><input type="text" name="@("email" + j.ToString())" value="@subscriber.Email" /></td>
                <td><input type="checkbox" name="@("log" + j.ToString())" @(subscriber.Logs ? "Checked" : "") /> Log
                <input type="checkbox" name="@("err" + j.ToString())"  @(subscriber.Errs ? "Checked" : "") /> Errors
                <input type="checkbox" name="@("dmp" + j.ToString())" @(subscriber.Dmps ? "Checked" : "") /> Dumps</td>
                <td></td>
                </tr>
              ++j;
          }
           <tr><td>Email:</td><td><input type="text" name="@("email" + j.ToString())" value="" /></td>
                <td><input type="checkbox" name="@("log" + j.ToString())" />
                Log<input type="checkbox" name="@("err" + j.ToString())"  /> Errors<input type="checkbox" name="@("dmp" + j.ToString())" /> Dumps</td>
                <td></td>
                </tr>
      }
    <tr><td colspan="4"><input type="submit" name="submit" value="Save" /></td></tr>
    </table>
    </form>
    </body>
</html>
